package be.nvlooy.moviereminder.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class SessionMessageInterceptor extends HandlerInterceptorAdapter {
	
	private SessionMessage sessionMessage;
	
	@Autowired
	public void setSessionMessage(SessionMessage sessionMessage) {
		this.sessionMessage = sessionMessage;
	}
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		String msg = sessionMessage.getMessage();
		
		if(msg != null)
			request.setAttribute(sessionMessage.getMessageTypeParameter(), msg);
		
		return super.preHandle(request, response, handler);
	}
	
}
